<?php
namespace app\admin\controller;
use think\Db;
use think\Controller;
use think\Request;

class Lj extends Controller{

    public function ljs(){
        $list = Db::table('lj')->select();
        return view('index/lj',[
            'title'=>'友情链接管理',
            'list'=>$list,
        ]);
    }

    public function create(){
        return view('index/ljadd',[
            'title'=>'友情链接添加页',
        ]);
    }


    public function save(Request $request){
        $p = Request::instance()->post();
//        dump($p);

        $data = [
            'ljname'=>$p['ljname'],
            'ljaddress'=>$p['ljaddress'],
            'ljstatus'=>$p['ljstatus'],
        ];

        $result = Db::table('lj')->data($data)->insert();

        if($result > 0){
            return $this->success('添加成功',url('admin/lj/ljs'));
        } else {
            return $this->error('添加失败');
        }


    }


    public function edits($id){
        $list = Db::table('lj')->field(true)->find($id);
        dump($list);
        return view('index/ljedit',[
            'title'=>'链接编辑',
            'list'=>$list,

        ]);
    }


    public function update(Request $request, $id){
        $info = $request->put();
//                dump($info);

        $data = [
            'ljname'=>$info['ljname'],
            'ljaddress'=>$info['ljaddress'],
            'ljstatus'=>$info['ljstatus'],

        ];
//        dump($data);die;

        $result = Db::table('lj')->where('id='.$id)->update($data);

        if ($result > 0) {
            return $this->success('编辑成功', url('admin/lj/ljs'));
        } else {
            return $this->success('编辑失败(ノ°ο°)ノ高能预警!');
        }


    }


    public function del($id){
        $result = Db::table('lj')->delete($id);
        if($result > 0){
            return $this->success('删除成功',url('admin/lj/ljs'));
        } else {
            return $this->error('删除失败');

        }
    }
}